package org.myorg.datastraemapi.demo;


import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.myorg.datastraemapi.model.Student;

import java.util.ArrayList;
import java.util.List;

public class MapDemo {
	public static void main(String[] args) throws Exception {
		final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

		List<Student> listSource = new ArrayList<Student>() {{
			add(new Student(1, 1));
			add(new Student(2, 2));
			add(new Student(3, 3));
			add(new Student(4, 4));
			add(new Student(5, 4));
			add(new Student(6, 4));
			add(new Student(7, 4));
		}};
		DataStreamSource<Student> dataStreamSource = env.fromCollection(listSource);

		SingleOutputStreamOperator<Student> map = dataStreamSource.map(new MapFunction<Student, Student>() {
			@Override
			public Student map(Student student) throws Exception {
				Student res = new Student();
				res.id = student.id;
				res.age = student.age + 5;
				return res;
			}
		});
		map.print();

		env.execute("Flink Streaming Java API Skeleton");
	}
}
